﻿myApp.controller("IntegralCtrl", ['$scope', '$http', '$routeParams', '$restUrls', '$post', '$rootScope', function ($scope, $http, $routeParams, $restUrls, $post, $rootScope) {
    var page = 1;
    $scope.IntegralList = [];
    $http({ method: "GET", url: $restUrls["getCustomerRewardRecords"], params: { page: 1, limit: 10 } }).success(function (result) {
        if (result.success == 1) {
            $scope.IntegralList = result.data.reward;
        }
    }).error(function (data, status, headers, config) {
        $.scojs_message('服务器忙,请稍候重试', $.scojs_message.TYPE_ERROR);
    });

    $('#integrallist').dropload({
        scrollArea: window,
        loadUpFn: function (me) {
            page = 1;
            $http({ method: "GET", url: $restUrls["getCustomerRewardRecords"], params: { page: page, limit: 10 } }).success(function (result) {
                if (result.success == 1) {
                    $scope.IntegralList = result.data.reward;
                    me.resetload();
                } else {
                    me.resetload();
                };
            });
        },
        loadDownFn: function (me) {
            page = page + 1;
            $http({ method: "GET", url: $restUrls["getCustomerRewardRecords"], params: { page: page, limit: 10 } }).success(function (result) {
                if (result.success == 1) {
                    for (var i = 0; i < result.data.reward.length; i++) {
                        $scope.IntegralList.push(result.data.reward[i]);
                    }
                    me.resetload();
                } else {
                    page = page - 1;
                    me.resetload();
                };
            }).error(function (data, status, headers, config) {
                page = page - 1;
                me.resetload();
            });
        }
    });
}]);

